<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\CommonController;
use App\Http\Controllers\Api\WorkTicketController;
use App\Http\Controllers\Api\WorkUserAuthController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/

// Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
//     return $request->user();
// });

// 维护人员认证路由（无需认证）
Route::prefix('work-user')->group(function () {
    Route::post('login', [WorkUserAuthController::class, 'login']);
    Route::post('register', [WorkUserAuthController::class, 'register']);
});

// 工单管理路由
Route::middleware('check.work.user')->group(function () {
    // 维护人员认证路由（需要认证）
    Route::prefix('work-user')->group(function () {
        Route::post('logout', [WorkUserAuthController::class, 'logout']);
        Route::get('profile', [WorkUserAuthController::class, 'profile']);
    });

    Route::get('work-tickets/worker-list', [WorkTicketController::class, 'workerList']);
    
    // 工单转接相关路由
    Route::get('work-tickets/my-transfer-list', [WorkTicketController::class, 'getMyTransferList']);
    Route::get('work-tickets/my-transfer-detail/{id}', [WorkTicketController::class, 'getMyTransferDetail']);
    Route::post('work-tickets/my-transfer-detail/{id}/accept', [WorkTicketController::class, 'acceptTransfer']);
    Route::post('work-tickets/my-transfer-detail/{id}/reject', [WorkTicketController::class, 'rejectTransfer']);
    Route::post('work-tickets/{id}/transfer', [WorkTicketController::class, 'transfer']);

    // 抢单相关路由
    Route::get('work-tickets/free-worker-list', [WorkTicketController::class, 'getFreeWorkerList']);
    Route::post('work-tickets/free-worker-list/{id}/accept', [WorkTicketController::class, 'acceptFreeWorkTicket']);
    // 工单基础操作
    Route::apiResource('work-tickets', WorkTicketController::class)->only(['index', 'show', 'update']);
});

Route::prefix('common')->group(function () {
    Route::get('qiniu-oss-sign', [CommonController::class, 'getQiniuOssSign']);
    Route::get('school-list', [CommonController::class, 'getSchoolList']);
});

